<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition template="/template.xhtml">

        <ui:define name="title">
            <h:outputText value="المنتجات"></h:outputText>
        </ui:define>
        
          <ui:define name="body">
            
       
            <!-- end of the form notifications -->
  <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>

            <h:form class="well form-inline">

                <center><h1>اضافة منتج جديد</h1></center>

                <div class="clear"></div>

                <h:outputLabel value="#{bundle.CreateItemLabel_itemName}" for="itemName" />
                <h:inputText id="itemName" value="#{itemController.selected.itemName}" title="#{bundle.CreateItemTitle_itemName}" required="true" requiredMessage="#{bundle.CreateItemRequiredMessage_itemName}"/>

                <div class="clear"></div>

                <h:outputLabel value="#{bundle.CreateItemLabel_itemType}" for="itemType" />
                <h:selectOneMenu id="itemType" value="#{itemController.selected.itemType}" title="#{bundle.CreateItemTitle_itemType}" >
                    <f:selectItems value="#{itemController.types}"/>
                </h:selectOneMenu>

                <div class="clear"></div>

                <h:outputLabel value="#{bundle.CreateItemLabel_countryID}" for="countryID" />
                <h:selectOneMenu id="countryID" value="#{itemController.selected.countryID}" title="#{bundle.CreateItemTitle_countryID}" >
                    <f:selectItems value="#{countryController.itemsAvailableSelectOne}"/>
                    <f:ajax render="factoryID" listener="#{itemController.itemListener}" event="valueChange"/>
                </h:selectOneMenu>

                <h:commandLink action="/country/List" value="#{bundle.Add_Country}" immediate="true"  />

                <div class="clear"></div>

                <h:outputLabel  value="#{bundle.CreateItemLabel_factoryID}" for="factoryID" />
                <h:selectOneMenu id="factoryID" value="#{itemController.factoryid}" title="#{bundle.CreateItemTitle_factoryID}" >
                    <f:selectItems value="#{itemController.factoryList}"/>
                </h:selectOneMenu>

                <h:commandLink action="/factory/List" value="#{bundle.Add_Factory}" immediate="true"  />
 <h:panelGroup    rendered="${limits==0}">
                <div class="clear"></div>
<h:outputLabel value="العدد" for="itemNum" />
<h:inputText id="itemNum" value="#{itemController.selected.pk_Count}" />
 <div class="clear"></div>
<h:outputLabel value="الوزن" for="itemq" />
<h:inputText id="itemq" value="#{itemController.selected.quantity}" />
 </h:panelGroup>
                <div class="clear"></div>
                <center>
                    <h:commandButton value="اضافه" action="#{itemController.create}" class="btn btn-primary" />
                </center>
            </h:form>

            <!-- start of the table -->
            <h:form>
                <center><h1> المنتجات </h1></center>
                <h:panelGroup rendered="#{itemController.items.rowCount > 0}">                    
                    <p:dataTable value="#{itemController.listItems}" var="item" paginator="true" rows="100"
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="100,200,300">

                        <p:column filterBy="#{item.itemName}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemTitle_itemName}"/>
                            </f:facet>
                            <h:outputText value="#{item.itemName}"/>
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemTitle_itemType}"/>
                            </f:facet>
                            <h:outputText value="#{itemController.mapType(item.itemType)}"/>
                        </p:column>

                        <p:column filterBy="#{item.factoryID.factoryName}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemTitle_factoryID}"/>
                            </f:facet>
                            <h:outputText value="#{item.factoryID.factoryName}"/>
                        </p:column>

                        <p:column filterBy="#{item.countryID.countryName}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemTitle_countryID}"/>
                            </f:facet>
                            <h:outputText value="#{item.countryID.countryName}"/>
                        </p:column>
                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="العدد"/>
                            </f:facet>
    <h:outputText value="#{item.pk_Count}"/>
                         
                        </p:column>
                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="الوزن"/>
                            </f:facet>
                               <h:outputText value="#{item.quantity}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <h:commandButton action="#{itemController.prepareView(item)}" value="#{bundle.ListItemViewLink}" styleClass="btn btn-primary"/>
                           <h:panelGroup    rendered="${limits==0}">
                            <h:outputText value=" "/>
                            <h:commandButton action="#{itemController.prepareEdit(item)}" value="#{bundle.ListItemEditLink}" styleClass="btn btn-primary"/>
                            <h:outputText value=" "/>
                            <h:commandButton action="#{itemController.destroy(item)}" value="#{bundle.ListItemDestroyLink}" styleClass="btn btn-primary"/>
                      </h:panelGroup>
                        </p:column>
                    </p:dataTable>
                </h:panelGroup>
            </h:form>
            <!-- end of the table -->

            <div class="clear"></div>
            <button style="margin-right: 500px;" class="btn btn-primary" type="button">اطبع</button>

            <!-- end of the container -->
        </ui:define>
    </ui:composition>
</html>

